package com.Liuhang.Dao;

import com.Liuhang.JDBC.util;
import com.Liuhang.entity.user;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Statement;

public class user_update extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println(req.getParameter("name"));
        Integer id = Integer.parseInt(req.getParameter("id"));
        String name = (String) req.getParameter("name");
        String Passwd = (String) req.getParameter("passwd");
        String sex = (String) req.getParameter("sex");
        Integer phone = Integer.valueOf(req.getParameter("phone"));
        Integer money = Integer.valueOf(req.getParameter("money"));

        try {
            String sql = "UPDATE `java01`.`t_emp` SET `name` = '"+name+"', `sex` = '"+sex+"', `phone` = "+phone+", `money` = "+money+", `passwd` = '"+Passwd+"' WHERE `id` = "+id+"";
            Statement st = util.getStatement();
            st.execute(sql);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        ServletContext context = this.getServletContext();
        context.getRequestDispatcher("/Emplist.jsp").forward(req,resp);

    }
}
